<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<jsp:include page="/head.jsp"></jsp:include>
</head>
<body>
<!--购物车-->
	<a href="javascript:seeCart()">
		<div id=""
			style="width: 48px; height: 48px; position: fixed; right: 30px; top: 50%; background: url(assets/img/购物车.png), no-repeat; z-index: 999999; cursor: pointer;">
			<!--个数-->
			<span id="cartItemNum" style="font-weight: bold; position: relative; color: red; display: block; width: 25px; height: 25px; background-color: transparent; border-radius: 50%; text-align: center; line-height: 15px;"></span>
		</div>
	</a>
</body>
</html>
<script>
		//查看购物车
		function seeCart() {
			$.post(
					"myCart.let",
					{},
					function(data){
						if(data.code == 1){//没有登录
							sys.toastr.warn("请用户先登录呀");
						}else if(data.code == 2){
							//没有添加商品
							sys.toastr.warn("购物车空空如也，快去添加商品吧");
						}else{
							window.location="myCart.jsp";
						}
					},
					"json"
					)
		}
		
		//浏览器加载完毕就要开启定时器 发送异步请求获取购物车中的商品数量
		/* window.onload = function (){
			
			var cartItemNum = $("#cartItemNum");
			
			//每过1.5s执行一次操作
			setInterval(function () {
		        $.post(
		        		"cartItemNum.let",
		        		{},
		        		function(data){
		        			cartItemNum.html(data.num);
		        		},
		        		"json"
		        		)
		    },500);
		} */
</script>